﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using DDOS.Camera;

namespace DDOS.Objects
{
    class Room
    {
        public static int cameraDistance = 50;
        public static ThirdPersonCamera3D camera = new ThirdPersonCamera3D(cameraDistance, Vector3.Zero, Vector3.Up, new Vector3(-MathHelper.ToRadians(70), ThirdPersonCamera3D.NO_MIN, ThirdPersonCamera3D.NO_MIN), new Vector3(MathHelper.ToRadians(70), ThirdPersonCamera3D.NO_MAX, ThirdPersonCamera3D.NO_MAX), Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), ScreenManager.Instance.GraphicsDevice.Viewport.AspectRatio, .1f, 100000f));
        List<Enemy> enemies;
        List<Wall> walls;
        List<TransitionObject> transitions;
        Player p;
        bool has_boss;

        public void InitializeComponents(Player pl)
        {
            //Load content from file

            enemies = new List<Enemy>();
            walls = new List<Wall>();
            transitions = new List<TransitionObject>();
            has_boss = false;

            p = pl;

            //Position the player
        }

        public void add_to_score(int i)
        {
            p.add_to_score(i);
        }

        public bool b()
        {
            check_boss();
            return has_boss;
        }

        public void check_boss()
        {
            foreach (Enemy e in enemies)
            {
                if (e.GetType() == typeof(Boss1))
                {
                    has_boss = true;
                }
            }
        }

        public void setPlayerPos(Vector2 pos)
        {
            Vector2 diff = pos - p.Coordinates;
            p.Coordinates = pos;
            p.boundingObject.Move(diff.X, diff.Y);
            p.boundingCircle.Move(diff.X, diff.Y);
        }

        public void Activate()
        {
            foreach (Enemy e in enemies)
            {
                CollisionEngine.Instance.Add(e.boundingObject);
                if(e.GetType() == typeof(Enemy0))
                    CollisionEngine.Instance.Add(((Enemy0)e).BoundingCircle);
            }
            foreach (Wall w in walls)
                CollisionEngine.Instance.Add(w.boundingObject);
            foreach (TransitionObject t in transitions)
                CollisionEngine.Instance.Add(t.boundingObject);
        }

        public void Deactivate()
        {
            foreach (Enemy e in enemies)
            {
                CollisionEngine.Instance.Remove(e.boundingObject);
                if (e.GetType() == typeof(Enemy0))
                    CollisionEngine.Instance.Remove(((Enemy0)e).BoundingCircle);
            }
            foreach (Wall w in walls)
                CollisionEngine.Instance.Remove(w.boundingObject);
            foreach (TransitionObject t in transitions)
                CollisionEngine.Instance.Remove(t.boundingObject);
        }

        public void add_enemy(Enemy enemy)
        {
            enemies.Add(enemy);
        }

        public void add_wall(Wall wall)
        {
            walls.Add(wall);
        }

        public void add_transition(TransitionObject transition)
        {
            transitions.Add(transition);
        }

        public void Update(GameTime game_time)
        {
            foreach (Enemy e in enemies)
            {
                e.Update(game_time);
            }
            foreach (Wall w in walls)
            {
                w.Update(game_time);
            }
            p.Update(game_time);
        }

        public void Draw()
        {
            foreach (Enemy e in enemies)
            {
                e.Draw();
            }
            foreach (Wall w in walls)
            {
                w.Draw();
            }
            foreach (TransitionObject t in transitions)
            {
                t.Draw();
            }
            p.Draw();
            
        }
    }
}
